package com.elitetyc.customview.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.SeekBar;

import com.elitetyc.customview.R;
import com.elitetyc.customview.custom.LuDaShiView;

import java.util.Timer;
import java.util.TimerTask;

public class LdsViewActivity extends AppCompatActivity {

    private SeekBar sb_seek;
    private LuDaShiView lds_view;
    private int progress =0 ;

    Timer timer = new Timer();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lds_view);
        sb_seek = findViewById(R.id.sb_seek);
        lds_view = findViewById(R.id.lds_view);

        sb_seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                lds_view.setCurrentNum(progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });



    }

    public void startAnin(View view) {

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (progress>100){
                    progress=0;
                }
                progress++;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        lds_view.setCurrentNum(progress);
                    }
                });
            }
        },0,100);
    }

    public void stopAnin(View view) {
        timer.cancel();

    }
}
